package com.hy.study.inputformat;

import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.RecordReader;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;

import java.io.IOException;

/**
 * 自定义一个切片处理
 *
 * @author huyong
 * @date 2024 年 01 月 31 日 10:41: 28
 */
public class WholeFileInputFormat extends FileInputFormat<Text, BytesWritable> {
    /**
     * 重写该方法读取文件
     *
     * @param split   the split to be read
     * @param context the information about the task
     *
     * @return
     *
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public RecordReader<Text, BytesWritable> createRecordReader(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException {
        WholeRecordReader wholeRecordReader = new WholeRecordReader();
        wholeRecordReader.initialize(split, context);
        return wholeRecordReader;
    }
}
